<?php
namespace Swiftx\DataType;
/**
 +-----------------------------------------------------------------------------------------------------------------------------
 * 字符串数据类型
 +-----------------------------------------------------------------------------------------------------------------------------
 * @author      胡永强 <odaytudio@gmail.com>
 * @since       2014-11-17
 * @copyright   Copyright (c) 2014-2015 Swiftx Inc.
 +-----------------------------------------------------------------------------------------------------------------------------
 */
class String {

	protected $_value;

    /**
     * 构造函数
     * @param null $value
     */
	public function __construct($value = null){
		$this->_value = $value;
	}

    /**
     * 判断字符串是否以特定字符串开头
     * ----------------------------------------------------------
     * @param string $string   被检测字符串
     * @param string $start    用作开头的串
     * ----------------------------------------------------------
     * @return bool
     */
    public static function StartAs($string, $start){
        $length = strlen($start);
        for($i=0;$i<$length;$i++)
            if($start[$i]!=$string[$i]) return false;
        return true;
    }

    /**
     * 字符串替换
     * ----------------------------------------------------------
     * @param string $string   原字符串
     * @param string $original 待替换字符
     * @param string $target   目标字符
     * ----------------------------------------------------------
     * @return string
     */
    public static function Replace($string, $original, $target){
        return str_replace($original,$target,$string);
    }

    /**
     * 字符串截取
     * @param string $string
     * @param int $start
     * @param null $length
     * @return string
     */
    public static function SubStr($string, $start, $length = null){
        if($length == null) return substr($string, $start);
        return substr($string, $start, $length);
    }
	
}